
def penta_iter():
    i = 1
    j = 4
    k = 3
    while True:
        yield i
        i += j
        j += k

print 'penta_iter test:'
count = 10
for i in penta_iter():
    print i
    count -= 1
    if count <= 0:
        break

class penta(object):
    def __init__(self):
        self._penta_iter = penta_iter()
        self._penta = []
        for i in self._penta_iter:
            self._penta.append(i)
            break
    
    def __getitem__(self, key):
        if key < len(self._penta):
            return self._penta[key]
        else:
            key += 1
            for i in self._penta_iter:
                self._penta.append(i)
                if len(self._penta) == key:
                    return i

print 'penta mapper test:'
pt = penta()
print pt[5]

from math import sqrt
def penta_test(p):
    adj = 1 + 24 * p
    r = int(sqrt(adj))
    if r * r != adj:
        return False
    return ((r + 1) % 6) == 0

print 'penta_test test:'
for i in xrange(100):
    if penta_test(i):
        print i

def find_panta():
    di = 0
    while True:
        d = pt[di]
        print d
        ji = 0
        while True:
            j = pt[ji]
            if pt[ji + 1] - j > d:
                break
            k = j + d
            if penta_test(k) and penta_test(j + k):
                return j, k
            ji += 1
        di += 1
    
print 'finding penta for euler project 44:'
print find_panta()